package com.jbit.dm212.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.jbit.dm212.common.PageInfoDTO;
import com.jbit.dm212.common.ResponseResult;
import com.jbit.dm212.common.ResponseResultUtils;
import com.jbit.dm212.entity.dto.DmItemSearchDTO;
import com.jbit.dm212.entity.po.CommonData;
import com.jbit.dm212.entity.po.DmArea;
import com.jbit.dm212.entity.po.DmItem;
import com.jbit.dm212.entity.vo.DmItemSearchVO;
import com.jbit.dm212.entity.vo.DmItemTypeVO;
import com.jbit.dm212.service.DmItemService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/search/api/p/list")
public class SearchController {
    @Resource
    DmItemService dmItemService;
    @PostMapping("/queryItemList")
    public ResponseResult queryItemList(@RequestBody DmItemSearchVO searchVO){
        DmItem item = new DmItem();
        //将searchVO 同名属性复制给item
        BeanUtil.copyProperties(searchVO,item);
        item.setItemType1Id(searchVO.getItemTypeId1());
        item.setItemType2Id(searchVO.getItemTypeId2());
        item.setItemName(searchVO.getKeyword());

        DmArea area = new DmArea();
        area.setId(searchVO.getAreaId());

        CommonData data = new CommonData();
        data.setCurrentPage(searchVO.getCurrentPage());
        data.setSort(searchVO.getSort());

        PageInfoDTO<DmItemSearchDTO> pageInfoDTO = dmItemService.getItemList(item,area,data);
        return ResponseResultUtils.sendSuccess(pageInfoDTO);
    }
}
